<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/murmur/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/murmur/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/murmur/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/murmur/images/logo.svg" color="#222">

<link rel="stylesheet" href="/murmur/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/murmur/","scheme":"Gemini","version":"8.0.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"disqus","storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}};
  </script>

  <meta name="description" content="第3章： 对象3.1 语法 对象有两种方式定义： 字面量的定义方式 var obj &#x3D; &amp;#123; &amp;#125; 构造函数的定义方式 var obj &#x3D; new Object();   构造函数和字面量的定义所生成的对象是一样的，两者的区别是：字面量可以添加多个键&#x2F;值对，但构造函数的定义如果想定义多个键&#x2F;值对，则必须逐个添加属性。  3.2 类型 JavaScript一共有6种主要类型：stri">
<meta property="og:type" content="article">
<meta property="og:title" content="《你不知道的JavaScript(上)》S02E03">
<meta property="og:url" content="https://gitee.com/lianghuilin/murmur.git/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E03/index.html">
<meta property="og:site_name" content="汇话板">
<meta property="og:description" content="第3章： 对象3.1 语法 对象有两种方式定义： 字面量的定义方式 var obj &#x3D; &amp;#123; &amp;#125; 构造函数的定义方式 var obj &#x3D; new Object();   构造函数和字面量的定义所生成的对象是一样的，两者的区别是：字面量可以添加多个键&#x2F;值对，但构造函数的定义如果想定义多个键&#x2F;值对，则必须逐个添加属性。  3.2 类型 JavaScript一共有6种主要类型：stri">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-12-01T14:24:10.000Z">
<meta property="article:modified_time" content="2020-12-01T15:07:13.178Z">
<meta property="article:author" content="William Leung">
<meta property="article:tag" content="你不知道的JavaScript">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://gitee.com/lianghuilin/murmur.git/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E03/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>《你不知道的JavaScript(上)》S02E03 | 汇话板</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?a49081c570a782a242cdf6e19e1a584d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/murmur/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">汇话板</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">设定目标，放慢步调，用温和的力量自我改革</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/murmur/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/murmur/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AC%AC3%E7%AB%A0%EF%BC%9A-%E5%AF%B9%E8%B1%A1"><span class="nav-number">1.</span> <span class="nav-text">第3章： 对象</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E8%AF%AD%E6%B3%95"><span class="nav-number">1.0.1.</span> <span class="nav-text">3.1 语法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E7%B1%BB%E5%9E%8B"><span class="nav-number">1.0.2.</span> <span class="nav-text">3.2 类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1"><span class="nav-number">1.0.2.0.1.</span> <span class="nav-text">内置对象</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E5%86%85%E5%AE%B9"><span class="nav-number">1.0.3.</span> <span class="nav-text">3.3 内容</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-1-%E5%8F%AF%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7%E5%90%8D"><span class="nav-number">1.0.3.0.1.</span> <span class="nav-text">3.3.1 可计算属性名</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-2-%E5%B1%9E%E6%80%A7%E4%B8%8E%E6%96%B9%E6%B3%95"><span class="nav-number">1.0.3.0.2.</span> <span class="nav-text">3.3.2 属性与方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-3-%E6%95%B0%E7%BB%84"><span class="nav-number">1.0.3.0.3.</span> <span class="nav-text">3.3.3 数组</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-4-%E8%B5%8B%E5%80%BC%E5%AF%B9%E8%B1%A1"><span class="nav-number">1.0.3.0.4.</span> <span class="nav-text">3.3.4 赋值对象</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-5-%E5%B1%9E%E6%80%A7%E6%8F%8F%E8%BF%B0%E7%AC%A6"><span class="nav-number">1.0.3.0.5.</span> <span class="nav-text">3.3.5 属性描述符</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-6-%E4%B8%8D%E5%8F%98%E6%80%A7"><span class="nav-number">1.0.3.0.6.</span> <span class="nav-text">3.3.6 不变性</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-7-Get"><span class="nav-number">1.0.3.0.7.</span> <span class="nav-text">3.3.7 [[Get]]</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-8-Put"><span class="nav-number">1.0.3.0.8.</span> <span class="nav-text">3.3.8 [[Put]]</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-9-Getter%E5%92%8CSetter"><span class="nav-number">1.0.3.0.9.</span> <span class="nav-text">3.3.9 Getter和Setter</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-3-10-%E5%AD%98%E5%9C%A8%E6%80%A7"><span class="nav-number">1.0.3.0.10.</span> <span class="nav-text">3.3.10 存在性</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-4-%E9%81%8D%E5%8E%86"><span class="nav-number">1.0.4.</span> <span class="nav-text">3.4 遍历</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-5-%E5%B0%8F%E7%BB%93"><span class="nav-number">1.0.5.</span> <span class="nav-text">3.5 小结</span></a></li></ol></li></ol></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">William Leung</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/murmur/archives">
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">文章</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/murmur/categories/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/murmur/tags/">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </section>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/lianghuilin/murmur.git/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E03/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/murmur/images/avatar.gif">
      <meta itemprop="name" content="William Leung">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="汇话板">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          《你不知道的JavaScript(上)》S02E03
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2020-12-01 22:24:10 / 修改时间：23:07:13" itemprop="dateCreated datePublished" datetime="2020-12-01T22:24:10+08:00">2020-12-01</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/murmur/categories/%E4%B8%80%E5%91%A8%E4%B8%80%E7%AB%A0%E5%89%8D%E7%AB%AF%E4%B9%A6/" itemprop="url" rel="index"><span itemprop="name">一周一章前端书</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.8k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>6 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="第3章：-对象"><a href="#第3章：-对象" class="headerlink" title="第3章： 对象"></a>第3章： 对象</h1><h3 id="3-1-语法"><a href="#3-1-语法" class="headerlink" title="3.1 语法"></a>3.1 语法</h3><ul>
<li>对象有两种方式定义：<ul>
<li>字面量的定义方式 <code>var obj = &#123; &#125;</code></li>
<li>构造函数的定义方式 <code>var obj = new Object();</code></li>
</ul>
</li>
<li>构造函数和字面量的定义所生成的对象是一样的，两者的区别是：字面量可以添加多个键/值对，但构造函数的定义如果想定义多个键/值对，则必须逐个添加属性。</li>
</ul>
<h3 id="3-2-类型"><a href="#3-2-类型" class="headerlink" title="3.2 类型"></a>3.2 类型</h3><ul>
<li>JavaScript一共有6种主要类型：<code>string</code>、<code>number</code>、<code>boolean</code>、<code>null</code>、<code>underfined</code>、<code>object</code>。但简单基本类型本身并不是对象。</li>
<li>实际上，JavaScript种有许多特殊的对象子类型，我们称之为复杂基本类型。比如函数，就是对象的一个子类型，它像普通对象一样但只可以调用，可以作为参数进行传递。除此之外，数组也是特殊的子对象类型。</li>
</ul>
<h5 id="内置对象"><a href="#内置对象" class="headerlink" title="内置对象"></a>内置对象</h5><ul>
<li>JavaScript种还有一些对象子类型，被称为内置对象：<code>String</code>、<code>Number</code>、<code>Boolean</code>、<code>Object</code>、<code>Function</code>、<code>Array</code>、<code>Date</code>、<code>RegExp</code>、<code>Error</code>。</li>
<li>这些内置对象表面上很像传统语音中的类型(type)或者类(class)，比如Java中的String类。但在JavaScript中，它们只是一些内置函数。可以通过这些内置函数通过构造函数的方式构造一个对应子类型的新对象。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> str = <span class="string">&#x27;i am a string&#x27;</span>;</span><br><span class="line"><span class="keyword">typeof</span> str; <span class="comment">//string</span></span><br><span class="line">str <span class="keyword">instanceof</span> <span class="built_in">String</span>;  <span class="comment">// false</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> strObj = <span class="keyword">new</span> <span class="built_in">String</span>(<span class="string">&#x27;i am a string&#x27;</span>);</span><br><span class="line"><span class="keyword">typeof</span> strObj;  <span class="comment">// object</span></span><br><span class="line">strObj <span class="keyword">instanceof</span> <span class="built_in">String</span>;   <span class="comment">// true</span></span><br></pre></td></tr></table></figure></li>
<li>原始值’i am a string’并不是一个对象，只是一个字面量，且是不可改变的值。当对这个字面量上执行一些操作的时候，比如获取长度时，JavaScript会自动把字符串字面量转换成一个String对象，而不需要显式的创建一个对象。同样的，数值和布尔字面量也会自动转成对象。</li>
<li>null和undefined只要字面量形式，而没有对应的构造形式。相反，Date只有构造形式，而没有字面量形式。</li>
<li>对于Object、Array、Function和RegExp来说，无论使用文字还是构造形式，都是对象不是字面量。因为相比起字面量创建对象，构造形式可以传入额外的参数。</li>
<li>Error对象一般很少在代码中显式创建，只是在抛出异常时被自动创建。</li>
</ul>
<h3 id="3-3-内容"><a href="#3-3-内容" class="headerlink" title="3.3 内容"></a>3.3 内容</h3><ul>
<li>对象的内容是由任意类型的值组成的，我们称之为属性。</li>
<li>但这只是它的表现形式。在引擎内部，这些值的存储方式是多种多样的，一般不会直接存在对象容器内部。存的只是名称，就像指针一样，指向真正存储的位置。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    a : <span class="number">2</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">myObj.a; <span class="comment">// 2</span></span><br><span class="line">myObj[<span class="string">&#x27;a&#x27;</span>]; <span class="comment">// 2</span></span><br></pre></td></tr></table></figure></li>
<li>访问对象的属性值可以使用.操作符或者[]操作符。</li>
<li>.语法通常被称为“属性访问”，[‘a’]语法通常被称为“键访问”。这两种语法的主要区别在于.操作符要求属性名满足标识符的命名规则，而[]语法可以接受任意字符串作为属性名，也就是说后者可以传递变量名。</li>
<li>如果你使用sring字面量以外的其他值作为属性名，那它会转换成一个字符串。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;&#125;;</span><br><span class="line">myObj[<span class="literal">true</span>] = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line">myObj[<span class="number">3</span>] = <span class="string">&#x27;bar&#x27;</span>;</span><br><span class="line">myObj[myObj] = <span class="string">&#x27;baz&#x27;</span>;</span><br><span class="line"></span><br><span class="line">myObj[<span class="string">&#x27;true&#x27;</span>]; <span class="comment">// &#x27;foo&#x27;</span></span><br><span class="line">myObj[<span class="string">&#x27;3&#x27;</span>]; <span class="comment">// &#x27;bar&#x27;</span></span><br><span class="line">myObj[<span class="string">&#x27;[object object]]&#x27;</span>]; <span class="comment">// &#x27;baz&#x27;</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h5 id="3-3-1-可计算属性名"><a href="#3-3-1-可计算属性名" class="headerlink" title="3.3.1 可计算属性名"></a>3.3.1 可计算属性名</h5><ul>
<li>上面提到，如果需要通过表达式来计算属性名，可以使用<code>myObj[prefix + name]</code>的方式。但使用字面量形式来声明时，这样做就不行的。</li>
<li>幸好ES6增加了可计算属性名，可以在字面量形式使用[]包裹一个表达式来当作属性名：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> prefix = <span class="string">&#x27;foo&#x27;</span>;</span><br><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    [prefix + <span class="string">&#x27;bar&#x27;</span>] : <span class="string">&#x27;hello&#x27;</span>,</span><br><span class="line">    [prefix + <span class="string">&#x27;baz&#x27;</span>] : <span class="string">&#x27;world&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line">myObj[<span class="string">&#x27;foobar&#x27;</span>];    <span class="comment">//hello</span></span><br><span class="line">myObj[<span class="string">&#x27;foobaz&#x27;</span>];    <span class="comment">//world</span></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
<li>可计算属性名通常用在ES6的符号(Symbol)，它是一种新的基础数据类型。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    [<span class="built_in">Symbol</span>.Something] : <span class="string">&#x27;hello world&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//有点类似vuex中store定义函数的用法</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h5 id="3-3-2-属性与方法"><a href="#3-3-2-属性与方法" class="headerlink" title="3.3.2 属性与方法"></a>3.3.2 属性与方法</h5><ul>
<li>在传统语言中，普通函数叫做函数，当函数属于某个对象时被称为“方法”。因此，也通常把“方法访问”说成是“方法访问”。</li>
<li>但在JavaScript中，函数永远不会真正“属于”一个对象，并没有把一个函数变成“方法”，函数和对象的关系，最多也只能是间接引用关系。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="built_in">console</span>..log(<span class="string">&#x27;foo&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> someFoo = foo;  <span class="comment">//对foo函数的变量引用</span></span><br><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    someFoo : someFoo</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//输出是一样的</span></span><br><span class="line">foo;</span><br><span class="line">someFoo;</span><br><span class="line">myObj.someFoo;</span><br></pre></td></tr></table></figure></li>
<li>所以，“函数”和“方法”在JavaScript中是一个东西。</li>
</ul>
<h5 id="3-3-3-数组"><a href="#3-3-3-数组" class="headerlink" title="3.3.3 数组"></a>3.3.3 数组</h5><ul>
<li>数组支持以[]的访问形式，期望通过填入整数的数值下标（索引）来获取数组中的元素。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">&#x27;foo&#x27;</span>,<span class="number">42</span>,<span class="string">&#x27;bar&#x27;</span>];</span><br><span class="line">arr.length; <span class="comment">//3</span></span><br><span class="line">arr[<span class="number">0</span>]; <span class="comment">//foo</span></span><br><span class="line">arr[<span class="number">2</span>]; <span class="comment">//42</span></span><br></pre></td></tr></table></figure></li>
<li>上文提到，数组是特殊的对象，所以也可以给数组添加属性：（但并不推荐这样做，还是应该用对象来存储键/值对，用数组来存储索引/值对）<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">&#x27;foo&#x27;</span>,<span class="number">42</span>,<span class="string">&#x27;bar&#x27;</span>];</span><br><span class="line">arr.baz = <span class="string">&#x27;baz&#x27;</span>;</span><br><span class="line">arr.length; <span class="comment">// 3  看到虽然可以给数组添加属性，但length值未发生变化</span></span><br><span class="line">arr.baz; <span class="comment">//baz</span></span><br></pre></td></tr></table></figure></li>
<li>当通过[]进行赋值时，如果属性名看起来像数字，就会被当做索引来使用，所以会直接改变到数组内的元素。</li>
</ul>
<h5 id="3-3-4-赋值对象"><a href="#3-3-4-赋值对象" class="headerlink" title="3.3.4 赋值对象"></a>3.3.4 赋值对象</h5><ul>
<li>JavaScript最常遇到的问题之一，就是如何复制一个对象。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">anotherFunction</span>(<span class="params"></span>)</span>&#123;&#125;</span><br><span class="line"><span class="keyword">var</span> anotherObj = &#123;</span><br><span class="line">    active : <span class="literal">true</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> anotherArr = [];</span><br><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    age : <span class="number">2</span>,</span><br><span class="line">    walk : anotherFunction,</span><br><span class="line">    alive : anotherObj,</span><br><span class="line">    scoreHistory : anotherArr</span><br><span class="line">&#125;</span><br><span class="line">anotherArr.push(anotherObj,myObj);</span><br></pre></td></tr></table></figure></li>
<li>我们首先要判断是浅复制还是深复制。如果是浅复制就比较简单了，比如要复制<code>myObj</code>这个对象，里面有值就复制值，有引用就复制引用。</li>
<li>比如ES6中的<code>Object.assign(targetObj,[sourceObj1,sourceObj2])</code>方法可以实现浅复制，参数一是目标对象，参数二可以是一个或多个的源对象。该方法会遍历一个或多个源对象中，所有可枚举的键，并把它们使用=操作符赋值到目标对象，最后返回目标对象。</li>
<li>但对于深复制就比较麻烦了，代码中<code>anotherArr</code>对象和<code>anotherObj</code>互相引用，这时该怎么办呢？为了解决这个棘手的问题，许多javascript框架都提出了自己的解决方案，但具体该采用哪种方法作为标准，没有明确的答案。</li>
</ul>
<h5 id="3-3-5-属性描述符"><a href="#3-3-5-属性描述符" class="headerlink" title="3.3.5 属性描述符"></a>3.3.5 属性描述符</h5><ul>
<li>ES5之前，JavaScript语言没有提供针对属性特性的描述符，比如属性是否只读等。但从ES5开始，所有的属性都具备属性描述符（也称为数据描述符）。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    a : <span class="number">2</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></li>
<li>比如<code>myObj.a</code>属性就包含四个描述符：<code>value</code>(值)、<code>writable</code>(可写)、<code>enumerable</code>(可枚举)、<code>configurable</code>(可配置)</li>
<li>ES5提供<code>Object.defineProperty()</code>方法新增或者修改属性并对属性特性进行配置：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;&#125;;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(myObj,<span class="string">&#x27;a&#x27;</span>,&#123;</span><br><span class="line">    value : <span class="number">2</span>,</span><br><span class="line">    writable : <span class="literal">true</span>,</span><br><span class="line">    configurable : <span class="literal">true</span>,</span><br><span class="line">    enumerable : <span class="literal">true</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li>
<li><strong>writable</strong> ：决定是否可以修改属性值。当值为false时，非严格模式下默认不能修改值，而在严格模式下，会抛出TypeError错误。</li>
<li><strong>configurable</strong> ：决定属性是否可配置。当值未false时，该属性就不能再通过<code>defineProperty()</code>方法进行修改，同时也无法<code>delete</code>该属性，否则会抛出一个TypeError错误。（注意：把<code>configurable</code>修改为false是单向操作，无法撤销）</li>
<li><strong>enumerable</strong> ：决定属性是否会出现在对象的属性枚举中，比如说<code>for in</code>循环。如果把enumerable设置为false，这个属性就不会出现在枚举中，但仍可以正常访问它。</li>
</ul>
<h5 id="3-3-6-不变性"><a href="#3-3-6-不变性" class="headerlink" title="3.3.6 不变性"></a>3.3.6 不变性</h5><ul>
<li>ES5中有多种方法来让对象或者对象的属性不可改变，但这些方法设置的都是浅不变性，也就是说，只会影响目标对象和它的直接属性，对象引用的其他对象不受影响，仍然是可变的。<ul>
<li><strong>对象变量</strong> ：结合<code>writable:false</code>和<code>configurable:false</code>可以创建一个不可修改、不可重新定义和删除的属性。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;&#125;;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(myObj,<span class="string">&#x27;NUMBER&#x27;</span>,&#123;</span><br><span class="line">  value : <span class="number">42</span>,</span><br><span class="line">  writable : <span class="literal">false</span>,</span><br><span class="line">  configurable : <span class="literal">false</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></li>
<li><strong>禁止扩展</strong> ：可以用<code>Object.preventExtensions()</code>方法一个对象只保留已有属性，而禁止添加新属性。如果修改，在非严格模式下默认失败，在严格模式下会报TypeError。</li>
<li><strong>密封</strong> ：用<code>Object.seal()</code>方法可以创建一个“密封”对象，密封后的对象，不能新增或删除属性，也不能重新配置属性的特性，但可以修改属性的值。</li>
<li><strong>冻结</strong> : 用<code>Object.freeze()</code>方法可以对一个对象设置级别最高的不可变性，它将禁止对于对象本身及其任意直属属性的修改。</li>
</ul>
</li>
</ul>
<h5 id="3-3-7-Get"><a href="#3-3-7-Get" class="headerlink" title="3.3.7 [[Get]]"></a>3.3.7 [[Get]]</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    a : <span class="number">2</span></span><br><span class="line">&#125;;</span><br><span class="line">myObj.a;    <span class="comment">//2</span></span><br><span class="line">myObj.b;    <span class="comment">//undefined</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>myObj.a</code>获取属性实际上是进行了<code>[[Get]]</code>操作（有点像函数调用：<code>[[Get]]()</code>）<ul>
<li>首先在对象中查找是否有名称相同的属性，如果找到就返回这个属性值；</li>
<li>如果没有找到名称相同的属性，则遍历可能存在的<code>[[Prototype]]</code>链（第五章会详细介绍）；</li>
<li>如果无论如何都没有找到名称相同的属性，那<code>[[Get]]</code>操作会返回<code>undefined</code>；</li>
</ul>
</li>
</ul>
<h5 id="3-3-8-Put"><a href="#3-3-8-Put" class="headerlink" title="3.3.8 [[Put]]"></a>3.3.8 [[Put]]</h5><ul>
<li>有可以获取数据的<code>[[Put]]</code>操作，就一定有对应的<code>[[Put]]</code>操作。</li>
<li>当<code>[[Put]]</code>被触发时，首先检查对象中是否已经存在这个属性，如果不存在，会执行更复杂的操作，会在第5章详细讨论。如果存在这个属性，会检查下面的这些内容：<ul>
<li>属性是否是访问描述符(参见3.3.9小结)，如果是描述符，并且存在setter</li>
<li>属性的数据描述符是否<code>writable</code>，如果是false，在非严格模式下静默失败，严格模式下抛出TypeError异常；</li>
<li>如果都不是，将该值设置为属性的值；</li>
</ul>
</li>
</ul>
<h5 id="3-3-9-Getter和Setter"><a href="#3-3-9-Getter和Setter" class="headerlink" title="3.3.9 Getter和Setter"></a>3.3.9 Getter和Setter</h5><ul>
<li>ES5中可以用getter和setter改写默认操作，但只能应用在单个属性上。getter是一个隐藏函数，会在获取属性值时调用。setter也是一个隐藏函数，会在设置属性值时调用。</li>
<li>如果一个对象属性同时定义了getter和setter时，该属性会被定义为“访问描述符”。对于访问描述符来说，JavaScript会忽略属性的value和writable的属性，而只关心set和get特性。<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    <span class="keyword">get</span> <span class="title">a</span>()&#123;</span><br><span class="line">        <span class="keyword">return</span> a;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(myObj,<span class="string">&#x27;b&#x27;</span>,&#123;</span><br><span class="line">    get : <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">this</span>.a * <span class="number">2</span>;</span><br><span class="line">    &#125;,</span><br><span class="line">    enumrable : <span class="literal">true</span></span><br><span class="line">&#125;);</span><br><span class="line">myObj.a;    <span class="comment">// 2</span></span><br><span class="line">myObj.b;    <span class="comment">// 4</span></span><br></pre></td></tr></table></figure></li>
<li>通常getter和setter是成对出现的，如果只设置了对象属性的getter，对属性进行set操作会被忽略。<h5 id="3-3-10-存在性"><a href="#3-3-10-存在性" class="headerlink" title="3.3.10 存在性"></a>3.3.10 存在性</h5></li>
<li>有个问题，我们进行属性访问时，返回值可能是undefined，而这个值有可能是属性存储中的undefined，也有可能是属性不存在而返回的undefined。那么应该如何区分呢？<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myObj = &#123;</span><br><span class="line">    a : <span class="number">2</span></span><br><span class="line">&#125;;</span><br><span class="line">(<span class="string">&quot;a&quot;</span> <span class="keyword">in</span> myObj); <span class="comment">//true</span></span><br><span class="line">(<span class="string">&quot;b&quot;</span> <span class="keyword">in</span> myObj); <span class="comment">//false</span></span><br><span class="line">myObj.hasOwnProperty(<span class="string">&quot;a&quot;</span>);  <span class="comment">// true</span></span><br><span class="line">myObj.hasOwnProperty(<span class="string">&quot;b&quot;</span>);  <span class="comment">// false</span></span><br></pre></td></tr></table></figure></li>
<li><code>in</code>操作符检查属性是否在对象以及其[[Prototype]]原型链中，而<code>hasOwnProperty()</code>则只会检查属性是否在对象中，不会检查[[Prototype]]原型链。</li>
<li>除了通过for循环来确定属性是否可枚举之外，<code>propertyIsEnumerable()</code>方法也可以检查属性名是否在对象中，并符合<code>enumerable:true</code>。</li>
<li>另外，<code>Object.keys()</code>和<code>Object.getOwnPropertyNames()</code>方法会返回对象中可枚举的属性数组。</li>
</ul>
<h3 id="3-4-遍历"><a href="#3-4-遍历" class="headerlink" title="3.4 遍历"></a>3.4 遍历</h3><ul>
<li>关于遍历属性值，除了可以用标准的for循环，ES5还增加了一些数组的辅助迭代器：<code>forEach()</code>、<code>every()</code>、<code>some()</code><ul>
<li><code>forEach()</code>会遍历数组中的所有值，并忽略回调函数的返回值；</li>
<li><code>every()</code>会一直运行直到回调函数返回false；</li>
<li><code>some()</code>会一直运行直到回调函数返回true；</li>
</ul>
</li>
<li>ES6增加了一种用来遍历数组的<code>for of</code>循环语法：<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> myArray = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> item <span class="keyword">of</span> myArray)&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(item);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 1</span></span><br><span class="line"><span class="comment">// 2</span></span><br><span class="line"><span class="comment">// 3</span></span><br></pre></td></tr></table></figure></li>
<li><code>for of</code>循环的工作原理是，会向被访问对象请求一个迭代器对象（<code>iterator</code>），然后通过调用迭代器对象的<code>next()</code>方法来遍历所有返回值。<code>next()</code>方法会返回形式为<code>&#123;value:...,done:...&#125;</code>的值，value是当前的遍历值，done是一个布尔值，表示十分还有可以遍历的值。</li>
</ul>
<h3 id="3-5-小结"><a href="#3-5-小结" class="headerlink" title="3.5 小结"></a>3.5 小结</h3><ul>
<li>JavaScript中的声明对象有两种方式：字面量形式和构造形式。字面量形式更常用，但构造形式可以提供更多选项。</li>
<li>对象是6个基础类型之一，对象还包含具有不同行为的特殊子类型，比如function。</li>
<li>对象就是键值对的集合。可以通过<code>.propName</code>或者<code>[propName]</code>语法来获取属性值。访问属性时，引擎实际上会调用内部默认的<code>[[Get]]</code>操作，<code>[[Get]]</code>操作会检查对象本身是否包含这个属性，如果没有找到还会查找[[Protype]]原型链。</li>
<li>属性的特性可以通过属性描述符来控制，比如<code>writable</code>和<code>configurable</code>。此外，<code>Object.preventExtensions()</code>、<code>Object.seal()</code>和<code>Obejct.freeze()</code>可以设置对象不可变性的级别。</li>
<li>属性不一定包含值，也有可能是具备了getter/setter的访问描述符。</li>
<li>可以使用ES6的<code>for...of</code>语法来遍历数组或对象中的值，<code>for...of</code>循环会寻找内置或自定义的<code>@@iterator</code>对象并调用它的<code>next()</code>方法来遍历数据值。</li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>William Leung
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/lianghuilin/murmur.git/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E03/" title="《你不知道的JavaScript(上)》S02E03">https://gitee.com/lianghuilin/murmur.git/reading_notes/《你不知道的JavaScript-上-》S02E03/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/murmur/tags/%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript/" rel="tag"># 你不知道的JavaScript</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/murmur/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E02/" rel="prev" title="《你不知道的JavaScript(上)》S02E02">
                  <i class="fa fa-chevron-left"></i> 《你不知道的JavaScript(上)》S02E02
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/murmur/reading_notes/%E3%80%8A%E4%BD%A0%E4%B8%8D%E7%9F%A5%E9%81%93%E7%9A%84JavaScript-%E4%B8%8A-%E3%80%8BS02E04/" rel="next" title="《你不知道的JavaScript(上)》S02E04">
                  《你不知道的JavaScript(上)》S02E04 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">William Leung</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">142k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:09</span>
  </span>
</div>
<div class="busuanzi-count">
    <span id="busuanzi_container_site_uv">
      本站访客数<span id="busuanzi_value_site_uv"></span>人次
    </span>
    <span id="busuanzi_container_site_pv">
        本站总访问量<span id="busuanzi_value_site_pv"></span>次
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/murmur/js/utils.js"></script><script src="/murmur/js/motion.js"></script><script src="/murmur/js/next-boot.js"></script>

  
















  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  

  

</body>
</html>
